#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;

/**
  * @方法: 简单题
  * @时间复杂度: o()
  * @空间复杂度: o()
  * @评价:
*/
bool isEqual(int *scnt, int *pcnt){
    for(int i=0;i<26;i++){
        if(scnt[i] != pcnt[i]) return false;
    }
    return true;
}
vector<int> findAnagrams(string s, string p) {
    vector<int> ans;
    if(s.length() < p.length()) return ans;
    int scnt[26] = {};
    int pcnt[26] = {};
    int left = 0;
    int right = 0;

    for(char ch : p){
        pcnt[ch - 'a']++;
    }

    for(right = 0;right < p.length();right++){
        scnt[s[right] - 'a']++;
    }

    if(isEqual(scnt, pcnt)){
        ans.push_back(0);
    }
    for(right = p.length();right < s.length(); right++){
        scnt[s[left] - 'a']--;
        scnt[s[right] - 'a']++;
        left++;
        if(isEqual(scnt,pcnt)){
            ans.push_back(left);
        }
    }
    return ans;
}

int main(){
    cout << "hello world" << endl;
    string s = "aaaaaaaaaa";
    string p = "aaaaaaaaaaaaa";
    vector<int> ans = findAnagrams(s,p);
    cout << "ans.size() = " << ans.size() << endl;
    return 0;
}